import json

from lxml import etree
import requests

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',

}
movies = []
for page in range(1,11):
    url = 'https://ssr1.scrape.center//page/{}'.format(page)
    resp = requests.get(url,headers=headers)
    tree = etree.HTML(resp.text)
    movie_lis = tree.xpath('//*[@id="index"]/div[1]/div[1]/div')
    for i in movie_lis:
        title = i.xpath('./div/div/div[2]/a/h2/text()')[0]
        score = i.xpath('./div/div/div[3]/p[1]/text()')[0].strip()
        movies.append({'title': title, 'score': score})

with open('movies.json', 'w', encoding='utf-8') as json_file:
    json.dump(movies, json_file, ensure_ascii=False, indent=4)
